package com.shengyuan.manage_os.utils;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.im.common.utils.ToastUtil;
import com.shengyuan.manage_os.view.CustomButton;


/**
 * Created by Lonze on 2016/8/20.
 */
public class ViewTools {

    private static final int ADD = 1;
    private static final int CHECK = 2;


    public static void showView(CustomButton button, CustomButton[] arr) {
        button.setSelected(true);
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != button) {
                arr[i].setSelected(false);
            }
        }
    }

    public static void changeTitle(RelativeLayout tabImage, TextView tabText, ImageView img1, ImageView img2, String title, int tab) {

        switch (tab) {
            case 1:
                tabText.setVisibility(View.GONE);
                tabImage.setVisibility(View.VISIBLE);
                img2.setVisibility(View.GONE);
                img1.setVisibility(View.VISIBLE);
                break;
            case 2:
                tabImage.setVisibility(View.INVISIBLE);
                img1.setVisibility(View.GONE);
                img2.setVisibility(View.VISIBLE);
                tabText.setText(title);
                tabText.setVisibility(View.VISIBLE);
                break;
            case 4:
                tabImage.setVisibility(View.GONE);
                tabText.setVisibility(View.VISIBLE);
                img1.setVisibility(View.GONE);
                img2.setVisibility(View.VISIBLE);
                tabText.setText(title);
                break;
            case 5:
                tabImage.setVisibility(View.GONE);
                tabText.setVisibility(View.VISIBLE);
                img1.setVisibility(View.GONE);
                img2.setVisibility(View.VISIBLE);
                tabText.setText(title);
                break;
        }

    }
    public static void changeTitle(RelativeLayout tabImage, TextView tabText, String title, int tab) {

        switch (tab) {
            case 1:
                tabText.setVisibility(View.GONE);
                tabImage.setVisibility(View.VISIBLE);
                break;
            case 2:
                tabImage.setVisibility(View.INVISIBLE);
                tabText.setText(title);
                tabText.setVisibility(View.VISIBLE);
                break;
            case 4:
                tabImage.setVisibility(View.GONE);
                tabText.setVisibility(View.VISIBLE);
                tabText.setText(title);
                break;
            case 5:
                tabImage.setVisibility(View.GONE);
                tabText.setVisibility(View.VISIBLE);
                tabText.setText(title);
                break;
        }

    }


    public static boolean isTopTask(String[] strs, String str) {
        boolean is = false;
        for (int i = 0; i < strs.length; i++) {
            if (str.equals(strs[i])) {
                is = true;
            }
        }
        return is;
    }

    public static String showSetting(final Activity context,final View view, int width, int height, final int tag,final String[] data) {
        View mPopWindowView;
        final String result = "";
        final PopupWindow mPopWindow;
        switch (tag){
            case ViewTools.ADD:
                mPopWindowView = context.getLayoutInflater().inflate(R.layout.pop_window_layout, null);
                break;
            case ViewTools.CHECK:
                mPopWindowView = context.getLayoutInflater().inflate(R.layout.pop_window_layout_2, null);
                break;
              default:
                  mPopWindowView = context.getLayoutInflater().inflate(R.layout.pop_window_layout_2, null);
                  break;
        }

// Focusable 为True，PopupWindow的点击事件才会相应
        mPopWindow = new PopupWindow(mPopWindowView, width, height, true);
// 必须在代码中设置一下背景色，点击外面不会隐藏此弹窗
        mPopWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
// Focusable 为False时，不执行则点击外面不会隐藏此弹窗
        mPopWindow.setOutsideTouchable(true);
        mPopWindow.setAnimationStyle(R.anim.push_back_down_in);
        mPopWindowView.findViewById(R.id.tv_1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(tag == ViewTools.CHECK){
                }else
                onClickPopWindowItemListener.onClick(R.id.tv_1);
                mPopWindow.dismiss();
            }
        });
        mPopWindowView.findViewById(R.id.tv_2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                onClickPopWindowItemListener.onClick(R.id.tv_2);
                mPopWindow.dismiss();
            }
        });
        mPopWindowView.findViewById(R.id.tv_3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                onClickPopWindowItemListener.onClick(R.id.tv_3);
                mPopWindow.dismiss();
            }
        });
        mPopWindowView.findViewById(R.id.tv_4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClickPopWindowItemListener.onClick(R.id.tv_4);
                mPopWindow.dismiss();
            }
        });


// 显示 默认显示View的正下方，可以使用重载方法设置偏移量来调整位置
        mPopWindow.showAsDropDown(view,-20,18);
        return null;


    }

    public static OnClickPopWindowItemListener onClickPopWindowItemListener;
    public interface OnClickPopWindowItemListener{
        void onClick(int itemID);
    }
    public void setOnClickPopWindowItemListener(OnClickPopWindowItemListener onClickPopWindowItemListener){
        this.onClickPopWindowItemListener = onClickPopWindowItemListener;
    }


}
